package com.matt.foundation.vo.course;

import com.matt.foundation.DO.ChildrenCourseItemDO;
import com.matt.foundation.constant.CourseConstant;
import com.matt.commons.dto.sso.StaffDTO;
import com.matt.foundation.utils.DateUtil;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2017/9/19
 * *******************************
 */
@Data
public class WebCourseListVo {

    private String planId;

    private Date courseDate;

    private String beginTime;

    private String endTime;

    private String teachingAreaName;

    private String teacherId;

    private String teacherName;

    private String teachingAreaId;

    private String earlyTitle;

    private int earlyWeek = 0;

    private int courseType = 0;

    private String courseEarlyId;

    private List<String> childrenNames;

    public static WebCourseListVo of(Object[] plans, List<ChildrenCourseItemDO> itemList, StaffDTO staff) {
        WebCourseListVo vo = new WebCourseListVo();
        vo.setPlanId(plans[0] == null ? "" : plans[0].toString());
        vo.setCourseDate(plans[1] == null ? null : (Date) plans[1]);
        vo.setBeginTime(plans[2] == null ? "" : DateUtil.millisToDateTime(((Date) plans[2]).getTime(), "HH:mm"));
        vo.setEndTime(plans[3] == null ? "" : DateUtil.millisToDateTime(((Date) plans[3]).getTime(), "HH:mm"));
        vo.setTeachingAreaId(plans[4] == null ? "" : plans[4].toString());
        vo.setTeachingAreaName(plans[5] == null ? "" : plans[5].toString());
        vo.setTeacherId(staff.getId());
        vo.setTeacherName(staff.getRealName());
        vo.setEarlyTitle(plans[7] == null ? "" : plans[7].toString());
        Integer courseType = Integer.valueOf(plans[8].toString());
        if (CourseConstant.CourseType.SAT.codeOf() == courseType){
            vo.setEarlyWeek(plans[10] == null ? 0 : Integer.valueOf(plans[10].toString()));
        }
        vo.setCourseType(courseType);
        vo.setCourseEarlyId(plans[9] == null ? "" : plans[9].toString());
        vo.setChildrenNames(itemList.stream().map(o->o.getName()).collect(Collectors.toList()));
        return vo;
    }
}
